package zheezes.eisp.startup.view;

import org.apache.log4j.PropertyConfigurator;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import zheezes.eisp.autotask.view.AutotaskWindow;
import zheezes.eisp.monitor.view.ToolkitWindow;
import zheezes.swt.util.SWTUtil;


public class StartupWindow {
	protected Shell shell;

	public static void main(String[] args) {
		PropertyConfigurator.configure("log4j.properties");
		try {
			StartupWindow window = new StartupWindow();
			window.open();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void open() {
		final Display display = Display.getDefault();
		createContents();
		shell.open();
		shell.layout();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
	}

	protected void createContents() {
		shell = new Shell(SWT.NONE);
		shell.setSize(266, 112);
		SWTUtil.setCenter(shell);

		final Button autoTaskButton = new Button(shell, SWT.NONE);
		autoTaskButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				AutotaskWindow.main(new String[0]); // main is marked as @Nonnull
			}
		});
		autoTaskButton.setText("button");
		autoTaskButton.setBounds(24, 28, 44, 23);

		final Button toolkitButton = new Button(shell, SWT.NONE);
		toolkitButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				ToolkitWindow.show();
			}
		});
		toolkitButton.setText("button");
		toolkitButton.setBounds(112, 28, 44, 23);
	}
}
